#!/bin/bash
WAIT_TIMEOUT=300
WAIT_INTERVAL=2
END_TIME=$(( $(date +%s) + WAIT_TIMEOUT ))
while [ $(date +%s) -lt $END_TIME ]; do
    if curl -sSf http://127.0.0.1:50000/actuator/health/readiness -o /dev/null; then
        echo "Java application is ready"
        curl -X POST http://127.0.0.1:50000/actuator/service-registry?status=UP -H "Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"
        exit 0
    fi
    sleep $WAIT_INTERVAL
done
echo "Timeout: Java application did not become ready within $WAIT_TIMEOUT seconds"
exit 1
